import {createSlice} from '@reduxjs/toolkit';

let zanSlice = createSlice({
  //别名
  name: 'zan',
  //初始值 initial初始化  state 状态   推荐设置为一个对象
  initialState: {
    value: 100
  },
  //配置 reducer 的功能 ,  配置 action 函数的功能
  reducers: {
    //新增的动作  state 状态值  action 操作对象  {type: , payload: 1}
    incre: (state, action) => {
      state.value += action.payload
    },
    //减的动作
    decre: (state, {payload}) => {
      state.value -= payload
    }
  }
})

//获取 action 的函数    incre(10) => {type: 'incre', payload: 10}
//暴露 action 函数
export let {incre, decre} = zanSlice.actions;

//暴露 reducer 函数
export default zanSlice.reducer;
